package com.javaweb.cwj.controller;


import com.javaweb.cwj.R;
import com.javaweb.cwj.entity.EduChapter;
import com.javaweb.cwj.entity.EduCourse;
import com.javaweb.cwj.entity.EduVideo;
import com.javaweb.cwj.entity.chapter.chapterVo;
import com.javaweb.cwj.entity.vo.CourseInfoVo;
import com.javaweb.cwj.service.EduChapterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2021-05-13
 */
@RestController
@RequestMapping("/eduService/cwj/chapter")
@CrossOrigin
public class EduChapterController {
     @Autowired
     private EduChapterService eduChapterService;
    @GetMapping("findChapterByCourseId/{courseId}")
    public R findChapterByCourseId(@PathVariable String courseId){
        List<chapterVo> chapterVoList = eduChapterService.findChapterBycourseId(courseId);
        return R.ok().data("chapterVoList",chapterVoList);
    }
    @PostMapping("addChapter")
   public R addChapter(@RequestBody EduChapter eduChapter){
        eduChapterService.save(eduChapter);
        return  R.ok();
   }
    @PostMapping("updateChapter")
    public R updateChapter(@RequestBody EduChapter eduChapter){
        eduChapterService.updateById(eduChapter);
        return  R.ok();
    }
    @DeleteMapping("deleteChapter/{id}")
    public R deleteChapter(@PathVariable String id){
        int i  = eduChapterService.deleteChapter(id);
        if(i>0){
            return  R.ok();
        }else{
            return R.error();
        }
    }
    @GetMapping("getChapterById/{chapterId}")
    public R getChapterById(@PathVariable String chapterId){
        EduChapter eduChapter = eduChapterService.getById(chapterId);
        return R.ok().data("eduChapter",eduChapter);
    }

}

